const TrumpCoin = artifacts.require("TrumpCoin");

module.exports = async function (deployer, network, accounts) {
  try {
    // 代币配置
    const tokenConfig = {
      name: "TrumpCoin",
      symbol: "TRUMP", 
      decimals: 18,
      initialSupply: web3.utils.toWei("1000000", "ether") // 100万代币
    };

    console.log(`🚀 Deploying ${tokenConfig.name} to ${network}`);
    console.log(`📝 Token: ${tokenConfig.symbol} (${tokenConfig.decimals} decimals)`);
    console.log(`💰 Initial Supply: ${web3.utils.fromWei(tokenConfig.initialSupply, 'ether')} ${tokenConfig.symbol}`);

    // 部署合约
    await deployer.deploy(
      TrumpCoin,
      tokenConfig.name,
      tokenConfig.symbol,
      tokenConfig.decimals,
      tokenConfig.initialSupply
    );

    const instance = await TrumpCoin.deployed();
    console.log(`✅ ${tokenConfig.name} deployed at: ${instance.address}`);

    // 验证部署
    const name = await instance.name();
    const symbol = await instance.symbol();
    const totalSupply = await instance.totalSupply();
    const deployerBalance = await instance.balanceOf(accounts[0]);

    console.log(`📋 Contract verified:`);
    console.log(`   Name: ${name}`);
    console.log(`   Symbol: ${symbol}`);
    console.log(`   Total Supply: ${web3.utils.fromWei(totalSupply.toString(), 'ether')}`);
    console.log(`   Deployer Balance: ${web3.utils.fromWei(deployerBalance.toString(), 'ether')}`);

  } catch (error) {
    console.error("❌ Deployment failed:", error);
    throw error;
  }
};